package com.diver.flinkdemo.service.impl;


import com.diver.flinkdemo.entity.xxt.DangerArea;
import com.diver.flinkdemo.service.IRedisService;
import com.diver.flinkdemo.utils.JedisUtil;

import java.io.IOException;
import java.util.List;

/**
 * Created by wenjun on 2018/7/6.
 */
//@Service
public class RedisServiceImpl implements IRedisService {
//    @Resource
//    private RedisTemplate<String, ?> redisTemplate;

    @Override
    public boolean set(final String key, final Object value) {
        return JedisUtil.set(key, value);
    }

    @Override
    public Object get(final String key, Class tClass) {
        return JedisUtil.get(key,tClass);
    }

    @Override
    public String get(final String key) {
        return JedisUtil.get(key);
    }

    @Override
    public List getList(String key, Class tClass) {
        try {
            return JedisUtil.getList(key,tClass);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean expire(final String key, int expire) {
        return JedisUtil.setExpire(key, expire);
    }

    @Override
    public boolean remove(final String key) {
        JedisUtil.del(key);
        return true;
    }

//    @Override
//    public void set(String key, Long expire, Object value) {
//        set(key, value);
//        expire(key, expire);
//    }

    /**
     * @param key
     * @param expire
     * @param value
     * @author yangs
     */
    @Override
    public void set(String key, Long expire, Object value) {
        JedisUtil.setEx(key,value,expire.intValue());
//        return result;
    }

    /**
     * @param key
     * @param expire
     * @param value
     * @author yangs
     */
    @Override
    public void set(String key, Long expire, String value) {
        JedisUtil.setEx(key,value,expire.intValue());
//        return result;
    }

    @Override
    public List<DangerArea> getDangerArea() {
        return this.getList("dangerArea:list", DangerArea.class);
    }
}
